<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
</head>
<body>
{include file="base/header" /}
<br/>
<div style="width: 600px;margin: 0 auto">
    <form class="layui-form" action="{:url('index/shelves/update')}" id="update" name="myform" method="post" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{$result.id}"/>
        <input type="hidden" name="bid" value="{$bid}"/>
        <input type="hidden" name="newcode" />
        <input type="hidden" name="newimage" />
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:150px;" >产品名称</label>
            <div class="layui-input-block">
                <input type="text" style="width: 400px"  value="{$result.pname}" name="pname" required  lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="width: 600px;margin-left: 40px">
            <label class="layui-form-label" style="width: 100px">添加人</label>
            <div class="layui-input-block" style="width: 400px">
                <select name="bid" lay-verify="required">
                    {foreach $linkman as $val}
                        <option value="{$val.id}" {if $val.id == $result.bid} selected {/if} >{$val.account}</option>
                    {/foreach}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
         <div class="layui-form-item layui-form-text">
            <label class="layui-form-label" style="width:150px;" >产品介绍</label>
            <div class="layui-input-block">
                <textarea name="introduce" style="width: 400px"  placeholder="请输入内容" class="layui-textarea">{$result.introduce}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label" style="width:150px;" >拍摄地址</label>
                <div class="layui-input-block">
                <textarea name="customer" style="width: 400px"  placeholder="请输入内容" class="layui-textarea">{$result.introduce}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:150px;" >进货价格(元)</label>
            <div class="layui-input-block">
                <input type="text" style="width: 400px" name="purchaseprice"  value="{$result.purchaseprice}" required  lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:150px;" >售价(元)</label>
            <div class="layui-input-block">
                <input type="text" style="width: 400px" name="retailprice"  required value="{$result.retailprice}" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:150px;" >条形码</label>
            <div class="layui-input-block">
                <input type="text" style="width: 400px" name="barcode"  required value="{$result.barcode}" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:150px;" >合作模式</label>
            <div class="layui-input-block">
                {if $result.cooperation == 1}
                <input type="text" style="width: 400px" value="进货价采购" name="cooperation"  required  lay-verify="required"  autocomplete="off" class="layui-input">
                {else/}
                <input type="text" style="width: 400px" value="少量货物月结" name="cooperation"  required  lay-verify="required"  autocomplete="off" class="layui-input">
                {/if}
            </div>
        </div>
        <div class="layui-form-item" style="width: 600px;margin-left: 40px">
            <label class="layui-form-label" style="width: 100px">类别</label>
            <div class="layui-input-block" style="width: 400px">
                <select name="category" lay-verify="required">
                    {foreach $title as $val}
                        <option value="{$val.title}" {if $val.title == $result.category} selected {/if} >{$val.title}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label" style="width:150px;">视频</label>-->
            <!--<div class="layui-input-block">-->
                <!--<button type="button" class="layui-btn" id="uploadvideo">-->
                    <!--<i class="layui-icon">&#xe67c;</i>上传视频-->
                <!--</button>-->
                <!--<label style="color: red">最下方为原视频</label>-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:150px;" >二维码</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="uploadcode">
                    <i class="layui-icon">&#xe67c;</i>上传二维码
                </button>
            </div>
        </div>
        <div class="layui-form-item" style="display: none" id="codes">
            <label class="layui-form-label" style="width:150px;" >新二维码</label>
            <div class="layui-input-block">
                <img src="" id="code" width="100px" height="100px"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:150px;" >原二维码</label>
            <div class="layui-input-block">
                <img src="__ROOT__\{$result.code}" width="100px" height="100px"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:150px;" >图片</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="uploadimage">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
            </div>
        </div>
        <div class="layui-form-item"  id="imgs"  style="display: none">
            <label class="layui-form-label" style="width:150px;">新图片</label>
            <div class="layui-input-block">
                <img src="" id="images" width="100px" height="100px"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:150px;" >原图片</label>
            <div class="layui-input-block">
                <img src="__ROOT__\{$result.image}" width="100px" height="100px"/>
            </div>
        </div>
        <div class="layui-form-item" style="width: 100px;margin-left: 300px">
            <button type="button" class="btn btn-info" id="uploads" onclick="sub()">修改</button>
        </div>
    </form>
</div>

<!--<video  src="__ROOT__\{$result.video}" width="600" height="600"  loop= loop controls="controls" autoplay="autoplay" >-->
<br/>
<br/>
</body>
<script>
    layui.use('carousel', function(){
        var carousel = layui.carousel;
        //建造实例
        carousel.render({
            elem: '#img',
            width: '100%',//设置容器宽度
            arrow: 'always' //始终显示箭头
            //anim: 'updown' //切换动画方式
        });
    });
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    //上传
    layui.use('upload', function(){
        var upload = layui.upload;
        var bid  = $("input[name=bid]").val();
        //上传视频
        upload.render({
            elem: '#uploadvideo' //绑定元素
            ,accept:'video'
            ,field:'video'
            ,done: function(res){
                //上传完毕回调
            }
            ,error: function(){
                //请求异常回调
            }
        });
        //上传二维码
        upload.render({
            elem: '#uploadcode' //绑定元素
            ,url:"{:url('index/shelves/uploadcode')}?bid="+bid
            ,field:'code'
            ,done: function(res){
                if(res.code){
                    $("#code").attr('src',"__ROOT__\\"+res.code);
                    $("#codes").css('display','block');
                    $("input[name=newcode]").val(res.code);
                }else if(res.error){
                    layer.alert(res.error);
                }
            }
        });
        //上传图片
        upload.render({
            elem: '#uploadimage' //绑定元素
            ,url:"{:url('index/shelves/uploadimage')}?bid="+bid
            ,field:'image'
            ,done: function(res){
                if(res.image){
                    $("#images").attr('src',"__ROOT__\\"+res.image);
                    $("#imgs").css('display','block');
                    $("input[name=newimage]").val(res.image);
                }else if(res.error){
                    layer.alert(res.error);
                }
            }
        });
    });
    //修改
    function sub() {
        $.ajax({
            url:"{:url('index/shelves/update')}",
            data:$("#update").serialize(),
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.alert(res.success,{btn:['确定']},function () {
                        window.location.reload();
                    })
                }else if(res.error){
                    layer.alert(res.error);
                }
            }
        });
    }
</script>
</html>